package com.ajk.server.model.request;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.collections4.CollectionUtils;
import org.springframework.web.multipart.MultipartFile;

import com.ajk.server.utils.FileStoreUtil;
import com.ajk.shop.model.Goods;
import com.ajk.shop.model.GoodsImage;

public class ShopGoodsReq extends Goods{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;


	private List<Integer> categoryIdList;

	private List<MultipartFile> addGoodsImageFiles;

	private List<GoodsImage> modifyGoodsImageList;

	private MultipartFile thumbnailImageFile;


	private List<String> addGoodsImagePaths;



	public List<Integer> getCategoryIdList() {
		return categoryIdList;
	}

	public void setCategoryIdList(List<Integer> categoryIdList) {
		this.categoryIdList = categoryIdList;
	}

	public List<MultipartFile> getAddGoodsImageFiles() {
		return addGoodsImageFiles;
	}

	public void setAddGoodsImageFiles(List<MultipartFile> addGoodsImageFiles) {
		this.addGoodsImageFiles = addGoodsImageFiles;
	}

	public List<GoodsImage> getModifyGoodsImageList() {
		return modifyGoodsImageList;
	}

	public void setModifyGoodsImageList(List<GoodsImage> modifyGoodsImageList) {
		this.modifyGoodsImageList = modifyGoodsImageList;
	}

	public MultipartFile getThumbnailImageFile() {
		return thumbnailImageFile;
	}

	public void setThumbnailImageFile(MultipartFile thumbnailImageFile) {
		this.thumbnailImageFile = thumbnailImageFile;
	}

	public List<String> getAddGoodsImagePaths() {
		return addGoodsImagePaths;
	}

	public void setAddGoodsImagePaths(List<String> addGoodsImagePaths) {
		this.addGoodsImagePaths = addGoodsImagePaths;
	}

	public Goods toGoods(){
		Goods goods = new Goods();
		if(getId()!=null){
			goods.setId(getId());
		}
		if(getQrCode()!=null){
			goods.setQrCode(getQrCode());
		}
		if(getCatId()!=null){
			goods.setCatId(getCatId());
		}
		if(getTitle()!=null){
			goods.setTitle(getTitle());
		}
		if(getModel()!=null){
			goods.setModel(getModel());
		}
		if(getSku()!=null){
			goods.setSku(getSku());
		}
		if(getSupplierId()!=null){
			goods.setSupplierId(getSupplierId());
		}
		if(getStockId()!=null){
			goods.setStockId(getStockId());
		}
		if(getLocation()!=null){
			goods.setLocation(getLocation());
		}
		if(getSubject()!=null){
			goods.setSubject(getSubject());
		}
		if(getDescription()!=null){
			goods.setDescription(getDescription());
		}
		if(getMarketPrice()!=null){
			goods.setMarketPrice(getMarketPrice());
		}
		if(getSalePrice()!=null){
			goods.setSalePrice(getSalePrice());
		}
		if(getAmount()!=null){
			goods.setAmount(getAmount());
		}
		if(getIsReal()!=null){
			goods.setIsReal(getIsReal());
		}
		if(getSortOrder()!=null){
			goods.setSortOrder(getSortOrder());
		}
		if(getIsHot()!=null){
			goods.setIsHot(getIsHot());
		}
		if(getIsRecommend()!=null){
			goods.setIsRecommend(getIsRecommend());
		}
		if(getThumbnailImage()!=null){
			goods.setThumbnailImage(getThumbnailImage());
		}
		if(getStockStatus()!=null){
			goods.setStockStatus(getStockStatus());
		}
		if(getIsOnsale()!=null){
			goods.setIsOnsale(getIsOnsale());
		}
		if(getSubtract()!=null){
			goods.setSubtract(getSubtract());
		}
		if(getCreateTime()!=null){
			goods.setCreateTime(getCreateTime());
		}
		if(getPostFree()!=null){
			goods.setPostFree(getPostFree());
		}
		if(getIsHomePage()!=null){
			goods.setIsHomePage(getIsHomePage());
		}
		if(getBuyCount()!=null){
			goods.setBuyCount(getBuyCount());
		}
		if(getIntrUrl()!=null){
			goods.setIntrUrl(getIntrUrl());
		}
		if(getIsExpress()!=null){
			goods.setIsExpress(getIsExpress());
		}
		if(getGoodsType()!=null){
			goods.setGoodsType(getGoodsType());
		}
		if(getIsUseCoupon()!=null){
			goods.setIsUseCoupon(getIsUseCoupon());
		}
		if(getManufacturer()!=null){
			goods.setManufacturer(getManufacturer());
		}
		if(getApprovalNumber()!=null){
			goods.setApprovalNumber(getApprovalNumber());
		}
		if(getBrand()!=null){
			goods.setBrand(getBrand());
		}


		return goods;
	}
	
	public void dealWith(){
		if(thumbnailImageFile!=null && thumbnailImageFile.getSize()>0){
			String path = FileStoreUtil.storeFile(thumbnailImageFile, "goods/thumbnail/");
			this.setThumbnailImage(path);
		}
		if (CollectionUtils.isNotEmpty(addGoodsImageFiles)) {
			for (MultipartFile multipartFile : addGoodsImageFiles) {
				if(multipartFile!=null && multipartFile.getSize()>0){
					String path = FileStoreUtil.storeFile(multipartFile, "goods/images/");
					if(addGoodsImagePaths==null){
						addGoodsImagePaths = new ArrayList<>();
					}
					addGoodsImagePaths.add(path);
				}
			}
		}
	}

}
